<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        style="width: 200px;"
        class="filter-item"
        placeholder="请输入登录名"
        v-model="queryForm.name"
      >
      </el-input>
      <el-input
        style="width: 200px;"
        class="filter-item"
        placeholder="请输入手机号"
        v-model="queryForm.phone"
      >
      </el-input>
      <el-select
        clearable
        style="width: 150px"
        class="filter-item"
        v-model="queryForm.status"
        placeholder="请选择用户状态"
      >
        <el-option
          v-for="(val, key) in Dicts.INVITE_STATUS"
          :key="key"
          :label="val"
          :value="key"
        >
        </el-option>
      </el-select>
      <el-button
        class="filter-item"
        @click="doQuery"
        type="primary"
        icon="el-icon-search"
        >查询</el-button
      >
    </div>
    <el-table
      v-loading="loading"
      @sort-change="handleSortChange"
      :data="records"
      style="width: 100%"
    >
      <el-table-column prop="rowId" label="ID" width="100" align="center">
      </el-table-column>
      <el-table-column align="center" prop="name" label="邀请人" width="150">
      </el-table-column>
      <el-table-column
        align="center"
        prop="phone"
        label="邀请人电话"
        width="150"
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="invitedName"
        label="被邀请人"
        width="150"
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="invitedPhone"
        label="被邀请人号码"
        width="150"
      >
        <!-- <template slot-scope="scope">
          <template v-if="scope.row.phone !== undefined">
            {{scope.row.phone.substr(0, 3) + '*****' + scope.row.phone.slice(8)}}
          </template>
        </template> -->
      </el-table-column>
      <el-table-column
        prop="companyName"
        label="公司名称"
        width="250"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="address"
        label="公司地址"
        width="250"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="businessLicense"
        label="营业执照"
        width="150"
        align="center"
      >
        <template slot-scope="scope">
          <div v-viewer>
            <img :src="$oss(scope.row.businessLicense)" width="40%" />
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="150" align="center">
        <template slot-scope="scope">
          {{ Dicts.INVITE_STATUS[scope.row.status] }}
        </template>
      </el-table-column>
      <el-table-column
        prop="invitedExpdate"
        label="邀请生效截止时间"
        width="250"
        align="center"
      >
      </el-table-column>
      <el-table-column
        width="200"
        fixed="right"
        align="center"
        label="操作"
        class-name="small-padding"
      >
        <template slot-scope="scope">
          <el-button
            v-permission="'realName:detail'"
            size="mini"
            type="info"
            @click="msgDialog(scope.row)"
            icon="el-icon-view"
            circle
            title="详情"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryForm.current"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="queryForm.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="queryForm.total"
      >
      </el-pagination>
    </div>

    <el-dialog :title="`详情`" :visible.sync="dialogMsgFormVisible" width="50%">
      <el-form :model="approveForm" label-width="150px" ref="approveForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="邀请人姓名:" prop="name">
              {{ approveForm.name }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邀请人电话:" prop="phone">
              {{ approveForm.phone }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="被邀请人姓名:" prop="invitedName">
              {{ approveForm.invitedName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="被邀请人电话:" prop="invitedPhone">
              {{ approveForm.invitedPhone }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="公司名称:" prop="companyName">
              {{ approveForm.companyName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司地址:" prop="address">
              {{ approveForm.address }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="邀请生效截止时间:" prop="invitedExpdate">
            {{ approveForm.invitedExpdate }}
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="营业执照:" prop="businessLicense">
            <img :src="$oss(approveForm.businessLicense)" width="60%" />
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="小区名称:" prop="communityNames">
              {{ approveForm.communityNames }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogMsgFormVisible = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { queryPropertyUserInvite } from '@/api/property'
import 'viewerjs/dist/viewer.css'
import Viewer from 'v-viewer'
import Vue from 'vue'
Vue.use(Viewer)

export default {
  data() {
    return {
      dialogFormVisible: false,
      loading: false,
      dialogApproveFormVisible: false,
      dialogMsgFormVisible: false,
      approveForm: [],
      queryForm: {
        current: 1,
        pages: 0,
        total: 0,
        size: 10,
        ascs: '',
        descs: '',
        importance: undefined,
        title: undefined
      },
      typeOptions: Dicts.EXAMPLE_TYPE,
      records: []
    }
  },
  created() {
    this.initOssClient().then(_ => {
      this.doQuery()
    })
  },
  methods: {
    handleSortChange({ column, prop, order }) {
      this.queryForm.ascs = ''
      this.queryForm.descs = ''
      if (order) {
        if (order === 'ascending') {
          this.queryForm.ascs = column.sortBy
        } else {
          this.queryForm.descs = column.sortBy
        }
      }
      this.queryForm.current = 0
      this.doQuery()
    },
    handleCurrentChange(current) {
      this.queryForm.current = current
      this.doQuery()
    },
    handleSizeChange(size) {
      this.queryForm.size = size
      this.doQuery()
    },
    doQuery() {
      this.loading = true
      queryPropertyUserInvite(this.queryForm).then(({ data: { data } }) => {
        this.queryForm.current = data.current
        this.queryForm.pages = data.pages
        this.queryForm.total = data.total
        this.queryForm.size = data.size
        this.records = data.records
        this.loading = false
      })
    },
    msgDialog({
      rowId,
      name,
      phone,
      address,
      companyName,
      businessLicense,
      invitedName,
      invitedPhone,
      invitedExpdate,
      communityNames
    }) {
      this.approveForm = {}
      this.dialogMsgFormVisible = true
      this.$refs.approveForm && this.$refs.approveForm.resetFields()
      this.approveForm.name = name
      this.approveForm.phone = phone
      this.approveForm.address = address
      this.approveForm.companyName = companyName
      this.approveForm.businessLicense = businessLicense
      this.approveForm.invitedName = invitedName
      this.approveForm.invitedPhone = invitedPhone
      this.approveForm.invitedExpdate = invitedExpdate
      this.approveForm.communityNames = communityNames
    }
  },
  components: {}
}
</script>

<style scoped></style>
